/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import thecliffproblem.Board;

/**
 *
 * @author Jaime
 */
public class ApplicationPanel extends JPanel{
    
    private BoardPanel boardPanel;
    private BoardEvaluationPanel boardEvaluationPanel;
    private ConfigurationPanel configurationPanel;
    private Board board;
 
    
    public ApplicationPanel(Board board, JFrame frame)
    {
        this.board = board;
        
        boardPanel = new BoardPanel(board, this);
        boardEvaluationPanel = new BoardEvaluationPanel(board);
        configurationPanel = new ConfigurationPanel(board, this);
        
        setLayout(new GridLayout(3, 0));
        
        add(boardPanel);
        add(boardEvaluationPanel);
        add(configurationPanel);
        
        JMenu menu = new JMenu("Help");
        JMenuItem helpItem = new JMenuItem("Help content");
        menu.add(helpItem);
        
        JMenuBar bar = new JMenuBar();
        bar.add(menu);
        
        frame.setJMenuBar(bar);
        
        helpItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "The first grid represents the environment, where:\n"
                        + "X = Current position\nS = Start position\nC = Cliff\nG = Goal\n\n"
                        + "The second grid represent the evaluation of each action at each state\n"
                        + "The actions are positioned in the square at the direction they refer to.\n"
                        + "You can set the delay between steps of the simulation (each step is an action), "
                        + "filling the field where it reads \"delay\" and pressing \"Set delay\".\n"
                        + "Press \"Run Episode\" to run one episode of the simulation.\n"
                        + "To run more than one episode at once, fill the field \"# of Episodes\" with "
                        + "the expected number of episodes and press \"Run Episodes\".", "HELP", JOptionPane.INFORMATION_MESSAGE);
            }
        });
        
        
    }
    
    public void repaintAll()
    {
        
        boardPanel.repaintAll();
        boardEvaluationPanel.repaintAll();
        revalidate();
        repaint();  
    }
    
    
    
    
}
